//
//  YTNewShareView.m
//  yitaicaijing
//
//  Created by DIANGHONG on 2018/8/6.
//  Copyright © 2018年 DIANGHONG. All rights reserved.
//

#import "YTNewShareView.h"
#import "YTNewShareCell.h"

@interface YTNewShareView()<UICollectionViewDataSource ,UICollectionViewDelegate>
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;


@end
@implementation YTNewShareView

+ (instancetype)shareViewWithFrame:(CGRect)frame
{
    UINib *nib = [UINib nibWithNibName:@"YTNewShareView" bundle:nil];
    YTNewShareView *view = [nib instantiateWithOwner:nil options:nil][0];
    view.frame = frame;
    return view;
}

- (void)awakeFromNib
{
    [super awakeFromNib];
    
    [self.collectionView registerNib:[UINib nibWithNibName:@"YTNewShareCell" bundle:nil] forCellWithReuseIdentifier:@"shareCellID"];
}

#pragma mark: - 取消按钮 点击监听
- (IBAction)cancelButtonClick:(UIButton *)sender
{
    NSAssert(self.cancelButtonClick != nil, @"cancelButtonClick 不能 nil");
    
    self.cancelButtonClick();
}

- (void)setShareList:(NSArray *)shareList
{
    _shareList = shareList;
    
    [self.collectionView reloadData];
}

#pragma mark: - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.shareList.count;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    YTNewShareCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"shareCellID" forIndexPath:indexPath];
    
    cell.dict = self.shareList[indexPath.row];
    return cell;
}



#pragma mark: - UICollectionViewDelegate
- ( CGSize )collectionView:( UICollectionView *)collectionView
                    layout:( UICollectionViewLayout *)collectionViewLayout
                    sizeForItemAtIndexPath:( NSIndexPath *)indexPath
{
    
    return CGSizeMake(kScreenWidth / 5, self.collectionView.bounds.size.height);
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSAssert(self.selectedSharaTypeToShare != nil, @"selectedSharaTypeToShare 不能 nil");

    self.selectedSharaTypeToShare([self.shareList[indexPath.row][@"type"] intValue]);
}



@end
